package com.dongdongshop.controller;

import com.dongdongshop.pojo.TbContent;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.ContentCategoryService;
import com.dongdongshop.service.ContentService;
import com.dongdongsop.data.AjaxResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("content")
public class ContentController {

    @DubboReference
    private ContentService contentService;

    @DubboReference
    private ContentCategoryService categoryService;

    //跳转前台首页
    @RequestMapping("toIndex")
    public String toIndex(){
        return "index";
    }

    //轮播图
    @RequestMapping("getSlideshow")
    @ResponseBody
    public AjaxResult getSlideshow(){
        try {
            List<TbContent> contentList = contentService.getSlideshow();
            return new AjaxResult().OK().setData(contentList);
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult().ERROR();
        }
    }

    //今日推荐
    @RequestMapping("getAboutUs")
    @ResponseBody
    public AjaxResult getAboutUs(){
        try {
            List<TbContent> contentList = contentService.getAboutUs();
            return new AjaxResult().OK().setData(contentList);
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult().ERROR();
        }
    }

    //猜你喜欢
    @RequestMapping("getRelated")
    @ResponseBody
    public AjaxResult getRelated(){
        try {
            List<TbContent> contentList = contentService.getRelated();
            return new AjaxResult().OK().setData(contentList);
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult().ERROR();
        }
    }

    @RequestMapping("banner/{categoryId}")//首页轮播图数据
    @ResponseBody
    public AjaxResult banner(@PathVariable("categoryId")Long categoryId){
        List<TbContent> tbContentList =contentService.selectByCategoryId(categoryId);
        return AjaxResult.OK().setData(tbContentList);
    }
}
